package cn.cttic.app.utils;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.util.Date;

/**
 * 订单助手
 */
@Component
public class OrderHelper {

    public String getSaleOrderId() {
        String orderId = "XS";
        orderId += DateUtil.format(new Date(), "yyMMddHHmmssSSS");
        return orderId;
    }

    public String getInstallOrderId() {
        String orderId = "AZ";
        orderId += DateUtil.format(new Date(), "yyMMddHHmmssSSS");
        return orderId;
    }

    /**
     * 获取安装码
     * @return 安装码
     */
    public  String getInstallCode() {

        LocalDate localDate = LocalDate.now();
        String year = number2Char(localDate.getYear() % 100);
        String month = number2Char(localDate.getMonthValue());
        String day = number2Char(localDate.getDayOfMonth());

        String seriaNo = IdWorker.getIdStr().substring(8, 15).toUpperCase();

        return day + year + month + seriaNo;
    }

    /**
     * 将数字转换为字母
     * @param number
     * @return
     */
    private  String number2Char(int number) {

        if (number < 10) {
            return "" + number;
        }

        number = number + 55;
        char ch = (char) number;

        return String.valueOf(ch);
    }
}
